package com.ymatou.app.rec.testcase;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;

import org.json.JSONArray;
import org.json.JSONObject;
import org.junit.After;
import org.junit.AfterClass;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;
import org.junit.experimental.categories.Category;

import com.ymatou.app.rec.parameter.SimProductBean;
import com.ymatou.app.rec.service.SimProductCall;
import com.ymt.core.tool.Logger;
import com.ymt.utils.annotation.TestCase;
import com.ymt.utils.tag.P1;
import com.ymttest.database.sqlwapper.CSearchWapper;
import com.ymttest.database.sqlwapper.SearchWapper;

public class Ts_SimProduct {
	private static SimProductBean simproductBean;
	private static SimProductCall simproductCall;
	
	@BeforeClass
	public static void setUp() {
		Logger.createResultFile("相似商品推荐接口");
	}

	@Before
	public void caseUp() {
		simproductBean = new SimProductBean();
		simproductCall = new SimProductCall();
	}

	@AfterClass
	public static void tearDown() {
		Logger.generateResult(simproductCall.getOpurl());
	}

	@After
	public void caseDown() {
		Logger.end();
	}
	
	@Test
	@Category(P1.class)
	@TestCase
	public void Tc_SimProduct_001() {
		Logger.start(true,"从买手进入商品详情页相似商品推荐-验证接口返回公共数据 ");
		try {
			//设置参数
			String requestid = "1111111";
			String module = "sellerdetailsimproduct";
			String platform = "appbuyer";
			String sort = "algo1";
			
			simproductBean.setInfo("userid:11,cookieid:22,idfa:33,imei:44,source:0,sproductid:06C3059A-9600-42D6-B944-40891894EB64,sort:"+sort+"");
			simproductBean.setAppkey("1");
			simproductBean.setRequestid(requestid);
			simproductBean.setModule(module);
			simproductBean.setPlatform(platform);
			simproductBean.setLimit("0,10");
			
			simproductCall.setData(simproductBean);
			simproductCall.callService();
			
			JSONArray hits = simproductCall.getHits();
			
			Logger.verifyEquals("OK",simproductCall.getCommonInfo("status") , "检查接口状态值");
			Logger.verifyNotNull(simproductCall.getCommonInfo("took"), "took不为空");
			Logger.verifyEquals(false, simproductCall.getCommonInfoBoo("downgrade"), "验证downgrade返回false");
			Logger.verifyEquals(false, simproductCall.getCommonInfoBoo("timeout"), "验证timeout返回flase");
			Logger.verifyEquals(requestid, simproductCall.getCommonInfo("requestid"), "验证requestid是否为所传值");
			Logger.verifyNotNull(simproductCall.getCommonInfo("hostip"), "hostip不为空");
			Logger.verifyEquals(sort, simproductCall.getCommonInfo("algorithm"), "验证返回排序算法是否为所传方法");
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	
	@Test
	@Category(P1.class)
	@TestCase
	public void Tc_SimProduct_002() {
		Logger.start(true,"从买手进入商品详情页相似商品推荐-检查接口返回数据，确保不会重复 ");
		try {
			//设置参数
			String productid = "06C3059A-9600-42D6-B944-40891894EB64";
			String requestid = "1111111";
			String module = "sellerdetailsimproduct";
			String platform = "appbuyer";
			String sort = "algo1";
			
			simproductBean.setInfo("userid:11,cookieid:22,idfa:33,imei:44,source:0,sproductid:"+productid+",sort:"+sort+"");
			simproductBean.setAppkey("1");
			simproductBean.setRequestid(requestid);
			simproductBean.setModule(module);
			simproductBean.setPlatform(platform);
			simproductBean.setLimit("0,10");
			
			simproductCall.setData(simproductBean);
			simproductCall.callService();
			
			Logger.verifyEquals("OK", simproductCall.getStatus(), "验证接口返回状态是否正常");
			JSONArray hitsAry = simproductCall.getHits();

			List<String> list = new ArrayList<String>();

			for (int i = 1; i <= hitsAry.length(); i++) {

				String ids = hitsAry.get(i - 1).toString();
				JSONObject json = new JSONObject(ids);

				String sproductid = json.getString("sproductid");

				if (list.contains(sproductid) == true) {

					Logger.verifyEquals(false, list.contains(sproductid), "验证第"+ i + "条返回数据的id存在重复值" + sproductid);

				} else {
					Logger.verifyEquals(false, list.contains(sproductid), "验证第"+ i + "条返回数据的id不存在重复值" + sproductid);

					list.add(sproductid);

				}
			}
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	
	@Test
	@Category(P1.class)
	@TestCase
	public void Tc_SimProduct_003() {
		Logger.start(true,"从买手进入商品详情页相似商品推荐-验证searchInfo里的返回数据 ");
		try {
			//设置参数
			String productid = "06C3059A-9600-42D6-B944-40891894EB64";
			String requestid = "1111111";
			String module = "sellerdetailsimproduct";
			String platform = "appbuyer";
			String sort = "algo1";
			
			simproductBean.setInfo("userid:11,cookieid:22,idfa:33,imei:44,source:0,sproductid:"+productid+",sort:"+sort+"");
			simproductBean.setAppkey("1");
			simproductBean.setRequestid(requestid);
			simproductBean.setModule(module);
			simproductBean.setPlatform(platform);
			simproductBean.setLimit("0,10");
			
			simproductCall.setData(simproductBean);
			simproductCall.callService();
			
			JSONObject searchInfoJsonObject= (JSONObject) simproductCall.getSearchInfo();
			Logger.verifyEquals(true, searchInfoJsonObject.has("module"), "验证searchInfo里是否有返回module模块字段信息");
			Logger.verifyEquals(true, searchInfoJsonObject.has("algo"), "验证searchInfo里是否有返回algo算法字段信息");
			Logger.verifyEquals(true, searchInfoJsonObject.has("yid"), "验证searchInfo里是否有返回yid字段信息");
			Logger.verifyEquals(module, searchInfoJsonObject.get("module"), "验证返回module值");
			Logger.verifyEquals(sort, searchInfoJsonObject.get("algo"), "验证返回algo值");
			Logger.verifyNotNull(searchInfoJsonObject.get("yid"), "验证返回yid不能为空");
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	
	@Test
	@Category(P1.class)
	@TestCase
	public void Tc_SimProduct_004() {
		Logger.start(true,"从买手进入商品详情页相似商品推荐-验证hits里的返回字段是否齐全 ");
		try {
			//设置参数
			String productid = "06C3059A-9600-42D6-B944-40891894EB64";
			String requestid = "1111111";
			String module = "sellerdetailsimproduct";
			String platform = "appbuyer";
			String sort = "algo1";
			
			simproductBean.setInfo("userid:11,cookieid:22,idfa:33,imei:44,source:0,sproductid:"+productid+",sort:"+sort+"");
			simproductBean.setAppkey("1");
			simproductBean.setRequestid(requestid);
			simproductBean.setModule(module);
			simproductBean.setPlatform(platform);
			simproductBean.setLimit("0,10");
			
			simproductCall.setData(simproductBean);
			simproductCall.callService();
			
			Logger.verifyEquals("OK", simproductCall.getStatus(), "验证接口返回状态是否正常");
			
			JSONArray hitsAry = simproductCall.getHits();
			
			for(int i=1;i<=hitsAry.length();i++){
				
			 String info = hitsAry.get(i-1).toString();
			 JSONObject infoAry = new JSONObject(info);
			 
			 //获取接口返回的key校验返回字段
			//  Logger.verifyEquals(true,infoAry.has("tags") , "验证第"+i+"条记录返回结果中有tag标签这个key");
			  Logger.verifyEquals(true,infoAry.has("sproductid") , "验证第"+i+"条记录返回结果中有sproductid关键字这个key");
			  Logger.verifyEquals(true,infoAry.has("source") , "验证第"+i+"条记录返回结果中有source值这个key");
			  
			}
		
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	
	@Test
	@Category(P1.class)
	@TestCase
	public void Tc_SimProduct_005() {
		Logger.start(true,"从买手进入商品详情页相似商品推荐-验证返回的sproductid是否有效 ");
		try {
			
			//设置参数
			String productid = "06C3059A-9600-42D6-B944-40891894EB64";
			String requestid = "1111111";
			String module = "sellerdetailsimproduct";
			String platform = "appbuyer";
			String sort = "algo1";
			
			simproductBean.setInfo("userid:2712477,cookieid:22,idfa:33,imei:44,source:0,sproductid:"+productid+",sort:"+sort+"");
			simproductBean.setAppkey("1");
			simproductBean.setRequestid(requestid);
			simproductBean.setModule(module);
			simproductBean.setPlatform(platform);
			simproductBean.setLimit("0,10");
			
			simproductCall.setData(simproductBean);
			simproductCall.callService();
			
			JSONArray hits = simproductCall.getHits();
			//Logger.verifyEquals("OK", simproductCall.getStatus(), "验证接口返回状态是否正常");
			
			for (int i = 1; i <= hits.length(); i++) {

				String info = hits.get(i - 1).toString();
				JSONObject infoAry = new JSONObject(info);
				
				//如果接口返回的source=1为商户查M端库。source=0为买手，查C端的库
				int sourcesInt =  (Integer) infoAry.get("source");
				
				String productId = (String) infoAry.get("sproductid");
				
			
				List<Map> ProductLists = null;
				if (sourcesInt==1) {
					
					//返回M端数据库里的商品信息
					 ProductLists = new SearchWapper().getProductBySellerId(0,"","",productId);
				}else{
					
					//返回C端数据库里的商品信息
					 ProductLists = new CSearchWapper().getProductById(productId);
				}
				
				Logger.verifyEquals(1, ProductLists.size(), "检查第"+i+"条商品id为："+productId+"的商品是否满足能都搜索出来的要求");
				
			}
		
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	
	@Test
	@Category(P1.class)
	@TestCase
	public void Tc_SimProduct_006() {
		Logger.start(true,"从买手进入商品详情页相似商品推荐-验证接口分页 ");
		try {
			//设置参数
			String productid = "06C3059A-9600-42D6-B944-40891894EB64";
			String requestid = "1111111";
			String module = "sellerdetailsimproduct";
			String platform = "appbuyer";
			String sort = "algo1";
			int limit = 2;
			
			simproductBean.setInfo("userid:11,cookieid:22,idfa:33,imei:44,source:0,sproductid:"+productid+",sort:"+sort+"");
			simproductBean.setAppkey("1");
			simproductBean.setRequestid(requestid);
			simproductBean.setModule(module);
			simproductBean.setPlatform(platform);
			simproductBean.setLimit("0,"+limit);
			
			simproductCall.setData(simproductBean);
			simproductCall.callService();
			
			JSONArray hits = simproductCall.getHits();
			
			Logger.verifyEquals(limit, hits.length(), "检查接口返回记录数是否为每页所传数目");
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	
	@Test
	@Category(P1.class)
	@TestCase
	public void Tc_SimProduct_007() {
		Logger.start(true,"商品详情页相似商品推荐-验证接口返回公共数据 ");
		try {
			//设置参数
			String productid = "06C3059A-9600-42D6-B944-40891894EB64";
			String requestid = "1111111";
			String module = "detailsimproduct";
			String platform = "appbuyer";
			String sort = "algo1";
			
			simproductBean.setInfo("userid:11,cookieid:22,idfa:33,imei:44,source:0,sproductid:"+productid+",sort:"+sort+"");
			simproductBean.setAppkey("1");
			simproductBean.setRequestid(requestid);
			simproductBean.setModule(module);
			simproductBean.setPlatform(platform);
			simproductBean.setLimit("0,10");
			
			simproductCall.setData(simproductBean);
			simproductCall.callService();
			
			JSONArray hits = simproductCall.getHits();
			
			Logger.verifyEquals("OK",simproductCall.getCommonInfo("status") , "检查接口状态值");
			Logger.verifyNotNull(simproductCall.getCommonInfo("took"), "took不为空");
			Logger.verifyEquals(false, simproductCall.getCommonInfoBoo("downgrade"), "验证downgrade返回false");
			Logger.verifyEquals(false, simproductCall.getCommonInfoBoo("timeout"), "验证timeout返回flase");
			Logger.verifyEquals(requestid, simproductCall.getCommonInfo("requestid"), "验证requestid是否为所传值");
			Logger.verifyNotNull(simproductCall.getCommonInfo("hostip"), "hostip不为空");
			Logger.verifyEquals(sort, simproductCall.getCommonInfo("algorithm"), "验证返回排序算法是否为所传方法");
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	
	@Test
	@Category(P1.class)
	@TestCase
	public void Tc_SimProduct_008() {
		Logger.start(true,"商品详情页相似商品推荐-检查接口返回数据，确保不会重复 ");
		try {
			//设置参数
			String productid = "06C3059A-9600-42D6-B944-40891894EB64";
			String requestid = "1111111";
			String module = "detailsimproduct";
			String platform = "appbuyer";
			String sort = "algo1";
			
			simproductBean.setInfo("userid:11,cookieid:22,idfa:33,imei:44,source:0,sproductid:"+productid+",sort:"+sort+"");
			simproductBean.setAppkey("1");
			simproductBean.setRequestid(requestid);
			simproductBean.setModule(module);
			simproductBean.setPlatform(platform);
			simproductBean.setLimit("0,10");
			
			simproductCall.setData(simproductBean);
			simproductCall.callService();
			
			Logger.verifyEquals("OK", simproductCall.getStatus(), "验证接口返回状态是否正常");
			JSONArray hitsAry = simproductCall.getHits();

			List<String> list = new ArrayList<String>();

			for (int i = 1; i <= hitsAry.length(); i++) {

				String ids = hitsAry.get(i - 1).toString();
				JSONObject json = new JSONObject(ids);

				String sproductid = json.getString("sproductid");

				if (list.contains(sproductid) == true) {

					Logger.verifyEquals(false, list.contains(sproductid), "验证第"+ i + "条返回数据的id存在重复值" + sproductid);

				} else {
					Logger.verifyEquals(false, list.contains(sproductid), "验证第"+ i + "条返回数据的id不存在重复值" + sproductid);

					list.add(sproductid);

				}
			}
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	
	@Test
	@Category(P1.class)
	@TestCase
	public void Tc_SimProduct_009() {
		Logger.start(true,"商品详情页相似商品推荐-验证searchInfo里的返回数据 ");
		try {
			//设置参数
			String productid = "06C3059A-9600-42D6-B944-40891894EB64";
			String requestid = "1111111";
			String module = "detailsimproduct";
			String platform = "appbuyer";
			String sort = "algo1";
			
			simproductBean.setInfo("userid:11,cookieid:22,idfa:33,imei:44,source:0,sproductid:"+productid+",sort:"+sort+"");
			simproductBean.setAppkey("1");
			simproductBean.setRequestid(requestid);
			simproductBean.setModule(module);
			simproductBean.setPlatform(platform);
			simproductBean.setLimit("0,10");
			
			simproductCall.setData(simproductBean);
			simproductCall.callService();
			
			JSONObject searchInfoJsonObject= (JSONObject) simproductCall.getSearchInfo();
			Logger.verifyEquals(true, searchInfoJsonObject.has("module"), "验证searchInfo里是否有返回module模块字段信息");
			Logger.verifyEquals(true, searchInfoJsonObject.has("algo"), "验证searchInfo里是否有返回algo算法字段信息");
			Logger.verifyEquals(true, searchInfoJsonObject.has("yid"), "验证searchInfo里是否有返回yid字段信息");
			Logger.verifyEquals(module, searchInfoJsonObject.get("module"), "验证返回module值");
			Logger.verifyEquals(sort, searchInfoJsonObject.get("algo"), "验证返回algo值");
			Logger.verifyNotNull(searchInfoJsonObject.get("yid"), "验证返回yid不能为空");
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	
	@Test
	@Category(P1.class)
	@TestCase
	public void Tc_SimProduct_010() {
		Logger.start(true,"商品详情页相似商品推荐-验证hits里的返回字段是否齐全 ");
		try {
			//设置参数
			String productid = "06C3059A-9600-42D6-B944-40891894EB64";
			String requestid = "1111111";
			String module = "detailsimproduct";
			String platform = "appbuyer";
			String sort = "algo1";
			
			simproductBean.setInfo("userid:11,cookieid:22,idfa:33,imei:44,source:0,sproductid:"+productid+",sort:"+sort+"");
			simproductBean.setAppkey("1");
			simproductBean.setRequestid(requestid);
			simproductBean.setModule(module);
			simproductBean.setPlatform(platform);
			simproductBean.setLimit("0,10");
			
			simproductCall.setData(simproductBean);
			simproductCall.callService();
			
			Logger.verifyEquals("OK", simproductCall.getStatus(), "验证接口返回状态是否正常");
			
			JSONArray hitsAry = simproductCall.getHits();
			
			for(int i=1;i<=hitsAry.length();i++){
				
			 String info = hitsAry.get(i-1).toString();
			 JSONObject infoAry = new JSONObject(info);
			 
			 //获取接口返回的key校验返回字段
			  //Logger.verifyEquals(true,infoAry.has("tags") , "验证第"+i+"条记录返回结果中有tag标签这个key");
			  Logger.verifyEquals(true,infoAry.has("sproductid") , "验证第"+i+"条记录返回结果中有sproductid关键字这个key");
			  Logger.verifyEquals(true,infoAry.has("source") , "验证第"+i+"条记录返回结果中有source值这个key");
			  
			}
		
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	
	@Test
	@Category(P1.class)
	@TestCase
	public void Tc_SimProduct_011() {
		Logger.start(true,"商品详情页相似商品推荐-验证返回的sproductid是否有效 ");
		try {
			//设置参数
			String productid = "06C3059A-9600-42D6-B944-40891894EB64";
			String requestid = "1111111";
			String module = "detailsimproduct";
			String platform = "appbuyer";
			String sort = "algo1";
			
			simproductBean.setInfo("userid:2712477,cookieid:22,idfa:33,imei:44,source:0,sproductid:"+productid+",sort:"+sort+"");
			simproductBean.setAppkey("1");
			simproductBean.setRequestid(requestid);
			simproductBean.setModule(module);
			simproductBean.setPlatform(platform);
			simproductBean.setLimit("0,10");
			
			simproductCall.setData(simproductBean);
			simproductCall.callService();
			
			Logger.verifyEquals("OK", simproductCall.getStatus(), "验证接口返回状态是否正常");
			
			for (int i = 1; i <= simproductCall.getHits().length(); i++) {

				String info = simproductCall.getHits().get(i - 1).toString();
				JSONObject infoAry = new JSONObject(info);
				
				//如果接口返回的source=1为商户查M端库。source=0为买手，查C端的库
				int sourcesInt =  (Integer) infoAry.get("source");
				
				String productId = (String) infoAry.get("sproductid");
				
				
				List<Map> ProductLists = null;
				if (sourcesInt==1) {
					//返回M端数据库里的商品信息
					 ProductLists = new SearchWapper().getProductBySellerId(0,"","",productId);
				}else{
					//返回C端数据库里的商品信息
					 ProductLists = new CSearchWapper().getProductById(productId);
				}
				
				Logger.verifyEquals(1, ProductLists.size(), "检查第"+i+"条商品id为："+productId+"的商品是否满足能都搜索出来的要求");
				
			}
		
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	
	@Test
	@Category(P1.class)
	@TestCase
	public void Tc_SimProduct_012() {
		Logger.start(true,"商品详情页相似商品推荐-验证接口分页 ");
		try {
			//设置参数
			String productid = "06C3059A-9600-42D6-B944-40891894EB64";
			String requestid = "1111111";
			String module = "detailsimproduct";
			String platform = "appbuyer";
			String sort = "algo1";
			int limit = 2;
			
			simproductBean.setInfo("userid:11,cookieid:22,idfa:33,imei:44,source:0,sproductid:"+productid+",sort:"+sort+"");
			simproductBean.setAppkey("1");
			simproductBean.setRequestid(requestid);
			simproductBean.setModule(module);
			simproductBean.setPlatform(platform);
			simproductBean.setLimit("0,"+limit);
			
			simproductCall.setData(simproductBean);
			simproductCall.callService();
			
			JSONArray hits = simproductCall.getHits();
			
			Logger.verifyEquals(limit, hits.length(), "检查接口返回记录数是否为每页所传数目");
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	
	@Test
	@Category(P1.class)
	@TestCase
	public void Tc_SimProduct_013() {
		Logger.start(true,"导购页相似商品推荐-验证接口返回公共数据 ");
		try {
			//设置参数
			String productid = "06C3059A-9600-42D6-B944-40891894EB64";
			String requestid = "1111111";
			String module = "daogousimproduct";
			String platform = "appbuyer";
			String sort = "algo1";
			
			simproductBean.setInfo("userid:11,cookieid:22,idfa:33,imei:44,source:0,sproductid:"+productid+",sort:"+sort+"");
			simproductBean.setAppkey("1");
			simproductBean.setRequestid(requestid);
			simproductBean.setModule(module);
			simproductBean.setPlatform(platform);
			simproductBean.setLimit("0,10");
			
			simproductCall.setData(simproductBean);
			simproductCall.callService();
			
			JSONArray hits = simproductCall.getHits();
			
			Logger.verifyEquals("OK",simproductCall.getCommonInfo("status") , "检查接口状态值");
			Logger.verifyNotNull(simproductCall.getCommonInfo("took"), "took不为空");
			Logger.verifyEquals(false, simproductCall.getCommonInfoBoo("downgrade"), "验证downgrade返回false");
			Logger.verifyEquals(false, simproductCall.getCommonInfoBoo("timeout"), "验证timeout返回flase");
			Logger.verifyEquals(requestid, simproductCall.getCommonInfo("requestid"), "验证requestid是否为所传值");
			Logger.verifyNotNull(simproductCall.getCommonInfo("hostip"), "hostip不为空");
			Logger.verifyEquals(sort, simproductCall.getCommonInfo("algorithm"), "验证返回排序算法是否为所传方法");
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	
	@Test
	@Category(P1.class)
	@TestCase
	public void Tc_SimProduct_014() {
		Logger.start(true,"导购页相似商品推荐-检查接口返回数据，确保不会重复 ");
		try {
			//设置参数
			String productid = "06C3059A-9600-42D6-B944-40891894EB64";
			String requestid = "1111111";
			String module = "daogousimproduct";
			String platform = "appbuyer";
			String sort = "algo1";
			
			simproductBean.setInfo("userid:11,cookieid:22,idfa:33,imei:44,source:0,sproductid:"+productid+",sort:"+sort+"");
			simproductBean.setAppkey("1");
			simproductBean.setRequestid(requestid);
			simproductBean.setModule(module);
			simproductBean.setPlatform(platform);
			simproductBean.setLimit("0,10");
			
			simproductCall.setData(simproductBean);
			simproductCall.callService();
			
			Logger.verifyEquals("OK", simproductCall.getStatus(), "验证接口返回状态是否正常");
			JSONArray hitsAry = simproductCall.getHits();

			List<String> list = new ArrayList<String>();

			for (int i = 1; i <= hitsAry.length(); i++) {

				String ids = hitsAry.get(i - 1).toString();
				JSONObject json = new JSONObject(ids);

				String sproductid = json.getString("sproductid");

				if (list.contains(sproductid) == true) {

					Logger.verifyEquals(false, list.contains(sproductid), "验证第"+ i + "条返回数据的id存在重复值" + sproductid);

				} else {
					Logger.verifyEquals(false, list.contains(sproductid), "验证第"+ i + "条返回数据的id不存在重复值" + sproductid);

					list.add(sproductid);

				}
			}
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	
	@Test
	@Category(P1.class)
	@TestCase
	public void Tc_SimProduct_015() {
		Logger.start(true,"导购页相似商品推荐-验证searchInfo里的返回数据 ");
		try {
			//设置参数
			String productid = "06C3059A-9600-42D6-B944-40891894EB64";
			String requestid = "1111111";
			String module = "daogousimproduct";
			String platform = "appbuyer";
			String sort = "algo1";
			
			simproductBean.setInfo("userid:11,cookieid:22,idfa:33,imei:44,source:0,sproductid:"+productid+",sort:"+sort+"");
			simproductBean.setAppkey("1");
			simproductBean.setRequestid(requestid);
			simproductBean.setModule(module);
			simproductBean.setPlatform(platform);
			simproductBean.setLimit("0,10");
			
			simproductCall.setData(simproductBean);
			simproductCall.callService();
			
			JSONObject searchInfoJsonObject= (JSONObject) simproductCall.getSearchInfo();
			Logger.verifyEquals(true, searchInfoJsonObject.has("module"), "验证searchInfo里是否有返回module模块字段信息");
			Logger.verifyEquals(true, searchInfoJsonObject.has("algo"), "验证searchInfo里是否有返回algo算法字段信息");
			Logger.verifyEquals(true, searchInfoJsonObject.has("yid"), "验证searchInfo里是否有返回yid字段信息");
			Logger.verifyEquals(module, searchInfoJsonObject.get("module"), "验证返回module值");
			Logger.verifyEquals(sort, searchInfoJsonObject.get("algo"), "验证返回algo值");
			Logger.verifyNotNull(searchInfoJsonObject.get("yid"), "验证返回yid不能为空");
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	
	@Test
	@Category(P1.class)
	@TestCase
	public void Tc_SimProduct_016() {
		Logger.start(true,"导购页相似商品推荐-验证hits里的返回字段是否齐全 ");
		try {
			//设置参数
			String productid = "06C3059A-9600-42D6-B944-40891894EB64";
			String requestid = "1111111";
			String module = "daogousimproduct";
			String platform = "appbuyer";
			String sort = "algo1";
			
			simproductBean.setInfo("userid:11,cookieid:22,idfa:33,imei:44,source:0,sproductid:"+productid+",sort:"+sort+"");
			simproductBean.setAppkey("1");
			simproductBean.setRequestid(requestid);
			simproductBean.setModule(module);
			simproductBean.setPlatform(platform);
			simproductBean.setLimit("0,10");
			
			simproductCall.setData(simproductBean);
			simproductCall.callService();
			
			Logger.verifyEquals("OK", simproductCall.getStatus(), "验证接口返回状态是否正常");
			
			JSONArray hitsAry = simproductCall.getHits();
			
			for(int i=1;i<=hitsAry.length();i++){
				
			 String info = hitsAry.get(i-1).toString();
			 JSONObject infoAry = new JSONObject(info);
			 
			 //获取接口返回的key校验返回字段
			  Logger.verifyEquals(true,infoAry.has("tag") , "验证第"+i+"条记录返回结果中有tag标签这个key");
			  Logger.verifyEquals(true,infoAry.has("sproductid") , "验证第"+i+"条记录返回结果中有sproductid关键字这个key");
			  Logger.verifyEquals(true,infoAry.has("source") , "验证第"+i+"条记录返回结果中有source值这个key");
			  
			}
		
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	
	@Test
	@Category(P1.class)
	@TestCase
	public void Tc_SimProduct_017() {
		Logger.start(true,"导购页相似商品推荐-验证返回的sproductid是否有效 ");
		try {
			//设置参数
			String productid = "06C3059A-9600-42D6-B944-40891894EB64";
			String requestid = "1111111";
			String module = "daogousimproduct";
			String platform = "appbuyer";
			String sort = "algo1";
			
			simproductBean.setInfo("userid:2712477,cookieid:22,idfa:33,imei:44,source:0,sproductid:"+productid+",sort:"+sort+"");
			simproductBean.setAppkey("1");
			simproductBean.setRequestid(requestid);
			simproductBean.setModule(module);
			simproductBean.setPlatform(platform);
			simproductBean.setLimit("0,10");
			
			simproductCall.setData(simproductBean);
			simproductCall.callService();
			
			Logger.verifyEquals("OK", simproductCall.getStatus(), "验证接口返回状态是否正常");
			
			for (int i = 1; i <= simproductCall.getHits().length(); i++) {

				String info = simproductCall.getHits().get(i - 1).toString();
				JSONObject infoAry = new JSONObject(info);
				
				//如果接口返回的source=1为商户查M端库。source=0为买手，查C端的库
				int sourcesInt =  (Integer) infoAry.get("source");
				
				String productId = (String) infoAry.get("sproductid");
				
				
				List<Map> ProductLists = null;
				if (sourcesInt==1) {
					//返回M端数据库里的商品信息
					 ProductLists = new SearchWapper().getProductBySellerId(0,"","",productId);
				}else{
					//返回C端数据库里的商品信息
					 ProductLists = new CSearchWapper().getProductById(productId);
				}
				
				Logger.verifyEquals(1, ProductLists.size(), "检查第"+i+"条商品id为："+productId+"的商品是否满足能都搜索出来的要求");
				
			}
		
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	
	@Test
	@Category(P1.class)
	@TestCase
	public void Tc_SimProduct_018() {
		Logger.start(true,"导购页相似商品推荐-验证接口分页 ");
		try {
			//设置参数
			String productid = "06C3059A-9600-42D6-B944-40891894EB64";
			String requestid = "1111111";
			String module = "daogousimproduct";
			String platform = "appbuyer";
			String sort = "algo1";
			int limit = 2;
			
			simproductBean.setInfo("userid:11,cookieid:22,idfa:33,imei:44,source:0,sproductid:"+productid+",sort:"+sort+"");
			simproductBean.setAppkey("1");
			simproductBean.setRequestid(requestid);
			simproductBean.setModule(module);
			simproductBean.setPlatform(platform);
			simproductBean.setLimit("0,"+limit+"");
			
			simproductCall.setData(simproductBean);
			simproductCall.callService();
			
			JSONArray hits = simproductCall.getHits();
			
			Logger.verifyEquals(limit, hits.length(), "检查接口返回记录数是否为每页所传数目");
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	
	
	@Test
	@Category(P1.class)
	@TestCase
	public void Tc_SimProduct_019() {
		Logger.start(true,"导购页相似商品推荐-验证返回商品是否满足匹配查找商品的二级类目或者品牌 ");
		/***
		 * 返回商品匹配规则：1.优先匹配与查找商品的二级类目相同的或者与查找商品品牌相同的商品。》2.匹配查找商品同商家的商品
		 * 排序规则：针对第一种方式会先从ex中取500条数据，然后通过根据商品名关键字匹配度高的排序，取前20个
		 * 针对第二种方式，直接取前20个
		 */
		
		try {
			//设置参数
			String requestid = "1111111";
			String module = "daogousimproduct";
			String platform = "appbuyer";
			String sort = "algo1";
			int limit = 20;
			//该商品是m端商品，二级类目是1252，品牌是10430
			String sproductid = "06C3059A-9600-42D6-B944-40891894EB64";
			
			simproductBean.setInfo("userid:11,cookieid:22,idfa:33,imei:44,source:0,sproductid:"+sproductid+",sort:"+sort+"");
			simproductBean.setAppkey("1");
			simproductBean.setRequestid(requestid);
			simproductBean.setModule(module);
			simproductBean.setPlatform(platform);
			simproductBean.setLimit("0,"+limit);
			
			simproductCall.setData(simproductBean);
			simproductCall.callService();
			
			//获取参数中的productid所属的类目和品牌
			List<Map> productInfo = new SearchWapper().selectProductInfo(sproductid);
			int paramIbrandid = (Integer) productInfo.get(0).get("iBrandId");
			int paramICategoryId = (Integer) productInfo.get(0).get("iCategoryId");
			
			//JSONArray hits = simproductCall.getHits();
			//验证返回的商品二级类目是否为1252或者品牌是否为10430
			//注意区分c端还是m端商品
			for (int i = 1; i <= simproductCall.getHits().length(); i++) {

				String info = simproductCall.getHits().get(i - 1).toString();
				JSONObject infoAry = new JSONObject(info);
				
				//如果接口返回的source=1为商户查M端库。source=0为买手，查C端的库
				int sourcesInt =  (Integer) infoAry.get("source");
				
				String productId = (String) infoAry.get("sproductid");
				
				List<Map> ProductLists = null;
				if (sourcesInt==1) {
					//返回M端数据库里该商品信息
					ProductLists = new SearchWapper().selectProductInfo(productId);
					int ibrandid = (Integer) ProductLists.get(0).get("iBrandId");
					int iCategoryId = (Integer) ProductLists.get(0).get("iCategoryId");
					
					
					if(paramIbrandid !=ibrandid && paramICategoryId !=iCategoryId){
						Logger.verifyEquals((paramIbrandid ==ibrandid || paramICategoryId ==iCategoryId),(paramIbrandid !=ibrandid && paramICategoryId !=iCategoryId) , 
								"验证第"+i+"条返回商品能够匹配到品牌或者类目");
					}
					
					if (paramIbrandid ==ibrandid || paramICategoryId ==iCategoryId) {
						Logger.verifyEquals(true, (paramIbrandid ==ibrandid || paramICategoryId ==iCategoryId), 
								"检查第"+i+"条返回商品品牌和类目能够匹配参数商品的品牌或类目.返回商品的类目："+iCategoryId+",品牌："+ibrandid+"。检索商品的类目:"+paramICategoryId+",品牌:"+paramIbrandid);
					}
			
				}else{
					//返回C端数据库里该商品信息
					ProductLists = new SearchWapper().selectProductInfo(productId);
					int ibrandid = (Integer) ProductLists.get(0).get("iBrandId");
					int iCategoryId = (Integer) ProductLists.get(0).get("iCategoryId");
					
					
					if(paramIbrandid !=ibrandid && paramICategoryId !=iCategoryId){
						Logger.verifyEquals((paramIbrandid ==ibrandid || paramICategoryId ==iCategoryId),(paramIbrandid !=ibrandid && paramICategoryId !=iCategoryId) , 
								"验证第"+i+"条返回商品能够匹配到品牌或者类目");
					}
					
					if (paramIbrandid ==ibrandid || paramICategoryId ==iCategoryId) {
						Logger.verifyEquals(true, (paramIbrandid ==ibrandid || paramICategoryId ==iCategoryId), 
								"检查第"+i+"条返回商品品牌和类目能够匹配参数商品的品牌或类目.返回商品的类目："+iCategoryId+",品牌："+ibrandid+"。检索商品的类目:"+paramICategoryId+",品牌:"+paramIbrandid);
					}
					
				}
				
			}
			
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	
	@Test
	@Category(P1.class)
	@TestCase
	public void Tc_SimProduct_020() {
		Logger.start(true,"导购页相似商品推荐-验证检索无匹配品牌和类目时，需要匹配商家id ");
		/***
		 * 返回商品匹配规则：1.优先匹配与查找商品的二级类目相同的或者与查找商品品牌相同的商品。》2.匹配查找商品同商家的商品
		 * 排序规则：针对第一种方式会先从ex中取500条数据，然后通过根据商品名关键字匹配度高的排序，取前20个
		 * 针对第二种方式，直接取前20个
		 */
		
		try {
			//设置参数
			String requestid = "1111111";
			String module = "daogousimproduct";
			String platform = "appbuyer";
			String sort = "algo1";
			int limit = 20;
			//该商品是m端商品，二级类目是1077，品牌是13259，该类目下只有2个有效商品，该品牌下有2个商品
			String sproductid = "06C3059A-9600-42D6-B944-40891894EB64";
			
			simproductBean.setInfo("userid:11,cookieid:22,idfa:33,imei:44,source:0,sproductid:"+sproductid+",sort:"+sort+"");
			simproductBean.setAppkey("1");
			simproductBean.setRequestid(requestid);
			simproductBean.setModule(module);
			simproductBean.setPlatform(platform);
			simproductBean.setLimit("0,"+limit);
			
			simproductCall.setData(simproductBean);
			simproductCall.callService();
			
			//获取检索商品的商家id
			List<Map> productInfo = new SearchWapper().selectProductInfo(sproductid);
			int paramIUserId = (Integer) productInfo.get(0).get("iUserId");
			int paramIbrandid = (Integer) productInfo.get(0).get("iBrandId");
			int paramICategoryId = (Integer) productInfo.get(0).get("iCategoryId");
			
			for (int i = 1; i <= simproductCall.getHits().length(); i++) {

				String info = simproductCall.getHits().get(i - 1).toString();
				JSONObject infoAry = new JSONObject(info);
				
				//如果接口返回的source=1为商户查M端库。source=0为买手，查C端的库
				int sourcesInt =  (Integer) infoAry.get("source");
				
				String productId = (String) infoAry.get("sproductid");
				
				List<Map> ProductLists = null;
				if (sourcesInt==1) {
					//返回M端数据库里该商品信息
					ProductLists = new SearchWapper().selectProductInfo(productId);
					int ibrandid = (Integer) ProductLists.get(0).get("iBrandId");
					int iCategoryId = (Integer) ProductLists.get(0).get("iCategoryId");
					int iuserId =  (Integer) ProductLists.get(0).get("iUserId");
					
					if(paramIbrandid !=ibrandid && paramICategoryId !=iCategoryId && paramIUserId !=iuserId){
						Logger.verifyEquals((paramIbrandid ==ibrandid || paramICategoryId ==iCategoryId),(paramIbrandid !=ibrandid && paramICategoryId !=iCategoryId) , 
								"验证第"+i+"条返回商品的品牌或者类目或者商家id与检索商品一致");
					}
					
					if (paramIbrandid ==ibrandid || paramICategoryId ==iCategoryId || paramIUserId==iuserId) {
						Logger.verifyEquals(true, (paramIbrandid ==ibrandid || paramICategoryId ==iCategoryId || paramIUserId==iuserId), 
								"检查第"+i+"条返回商品品牌或类目或商家id能够匹配参数商品的品牌或类目或商家id.返回商品的类目："+iCategoryId+",品牌："+ibrandid+"，商家id："+iuserId+"。检索商品的类目:"+paramICategoryId+",品牌:"+paramIbrandid+",商家id:"+paramIUserId);
					}
			
				}else{
					//返回C端数据库里该商品信息
					ProductLists = new SearchWapper().selectProductInfo(productId);
					int ibrandid = (Integer) ProductLists.get(0).get("iBrandId");
					int iCategoryId = (Integer) ProductLists.get(0).get("iCategoryId");
					int iuserId =  (Integer) ProductLists.get(0).get("iUserId");
					
					if(paramIbrandid !=ibrandid && paramICategoryId !=iCategoryId && paramIUserId !=iuserId){
						Logger.verifyEquals((paramIbrandid ==ibrandid || paramICategoryId ==iCategoryId),(paramIbrandid !=ibrandid && paramICategoryId !=iCategoryId) , 
								"验证第"+i+"条返回商品的品牌或者类目或者商家id与检索商品一致");
					}
					
					if (paramIbrandid ==ibrandid || paramICategoryId ==iCategoryId || paramIUserId==iuserId) {
						Logger.verifyEquals(true, (paramIbrandid ==ibrandid || paramICategoryId ==iCategoryId || paramIUserId==iuserId), 
								"检查第"+i+"条返回商品品牌或类目或商家id能够匹配参数商品的品牌或类目或商家id.返回商品的类目："+iCategoryId+",品牌："+ibrandid+"，商家id："+iuserId+"。检索商品的类目:"+paramICategoryId+",品牌:"+paramIbrandid+",商家id:"+paramIUserId);
					}
					
				}
				
			}
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	

	@Test
	@Category(P1.class)
	@TestCase
	public void Tc_SimProduct_021() {
		Logger.start(true,"购物车失效商品相似商品推荐-验证接口返回公共数据 ");
		try {
			//设置参数
			String sproductid = "06C3059A-9600-42D6-B944-40891894EB64";
			String requestid = "1111111";
			String module = "shoppingcarsimproduct";
			String platform = "appbuyer";
			String sort = "algo1";
			
			simproductBean.setInfo("userid:11,cookieid:22,idfa:33,imei:44,source:0,sproductid:"+sproductid+",sort:"+sort+"");
			simproductBean.setAppkey("1");
			simproductBean.setRequestid(requestid);
			simproductBean.setModule(module);
			simproductBean.setPlatform(platform);
			simproductBean.setLimit("0,10");
			
			simproductCall.setData(simproductBean);
			simproductCall.callService();
			
			JSONArray hits = simproductCall.getHits();
			
			Logger.verifyEquals("OK",simproductCall.getCommonInfo("status") , "检查接口状态值");
			Logger.verifyNotNull(simproductCall.getCommonInfo("took"), "took不为空");
			Logger.verifyEquals(false, simproductCall.getCommonInfoBoo("downgrade"), "验证downgrade返回false");
			Logger.verifyEquals(false, simproductCall.getCommonInfoBoo("timeout"), "验证timeout返回flase");
			Logger.verifyEquals(requestid, simproductCall.getCommonInfo("requestid"), "验证requestid是否为所传值");
			Logger.verifyNotNull(simproductCall.getCommonInfo("hostip"), "hostip不为空");
			Logger.verifyEquals(sort, simproductCall.getCommonInfo("algorithm"), "验证返回排序算法是否为所传方法");
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	
	@Test
	@Category(P1.class)
	@TestCase
	public void Tc_SimProduct_022() {
		Logger.start(true,"购物车失效商品相似商品推荐-检查接口返回数据，确保不会重复 ");
		try {
			//设置参数
			String productid = "06C3059A-9600-42D6-B944-40891894EB64";
			String requestid = "1111111";
			String module = "shoppingcarsimproduct";
			String platform = "appbuyer";
			String sort = "algo1";
			
			simproductBean.setInfo("userid:11,cookieid:22,idfa:33,imei:44,source:0,sproductid:"+productid+",sort:"+sort+"");
			simproductBean.setAppkey("1");
			simproductBean.setRequestid(requestid);
			simproductBean.setModule(module);
			simproductBean.setPlatform(platform);
			simproductBean.setLimit("0,10");
			
			simproductCall.setData(simproductBean);
			simproductCall.callService();
			
			Logger.verifyEquals("OK", simproductCall.getStatus(), "验证接口返回状态是否正常");
			JSONArray hitsAry = simproductCall.getHits();

			List<String> list = new ArrayList<String>();

			for (int i = 1; i <= hitsAry.length(); i++) {

				String ids = hitsAry.get(i - 1).toString();
				JSONObject json = new JSONObject(ids);

				String sproductid = json.getString("sproductid");

				if (list.contains(sproductid) == true) {

					Logger.verifyEquals(false, list.contains(sproductid), "验证第"+ i + "条返回数据的id存在重复值" + sproductid);

				} else {
					Logger.verifyEquals(false, list.contains(sproductid), "验证第"+ i + "条返回数据的id不存在重复值" + sproductid);

					list.add(sproductid);

				}
			}
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	
	@Test
	@Category(P1.class)
	@TestCase
	public void Tc_SimProduct_023() {
		Logger.start(true,"购物车失效商品相似商品推荐-验证searchInfo里的返回数据 ");
		try {
			//设置参数
			String productid = "06C3059A-9600-42D6-B944-40891894EB64";
			String requestid = "1111111";
			String module = "shoppingcarsimproduct";
			String platform = "appbuyer";
			String sort = "algo1";
			
			simproductBean.setInfo("userid:11,cookieid:22,idfa:33,imei:44,source:0,sproductid:"+productid+",sort:"+sort+"");
			simproductBean.setAppkey("1");
			simproductBean.setRequestid(requestid);
			simproductBean.setModule(module);
			simproductBean.setPlatform(platform);
			simproductBean.setLimit("0,10");
			
			simproductCall.setData(simproductBean);
			simproductCall.callService();
			
			JSONObject searchInfoJsonObject= (JSONObject) simproductCall.getSearchInfo();
			Logger.verifyEquals(true, searchInfoJsonObject.has("module"), "验证searchInfo里是否有返回module模块字段信息");
			Logger.verifyEquals(true, searchInfoJsonObject.has("algo"), "验证searchInfo里是否有返回algo算法字段信息");
			Logger.verifyEquals(true, searchInfoJsonObject.has("yid"), "验证searchInfo里是否有返回yid字段信息");
			Logger.verifyEquals(module, searchInfoJsonObject.get("module"), "验证返回module值");
			Logger.verifyEquals(sort, searchInfoJsonObject.get("algo"), "验证返回algo值");
			Logger.verifyNotNull(searchInfoJsonObject.get("yid"), "验证返回yid不能为空");
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	
	@Test
	@Category(P1.class)
	@TestCase
	public void Tc_SimProduct_024() {
		Logger.start(true,"购物车失效商品相似商品推荐-验证hits里的返回字段是否齐全 ");
		try {
			//设置参数
			String productid = "06C3059A-9600-42D6-B944-40891894EB64";
			String requestid = "1111111";
			String module = "shoppingcarsimproduct";
			String platform = "appbuyer";
			String sort = "algo1";
			
			simproductBean.setInfo("userid:11,cookieid:22,idfa:33,imei:44,source:0,sproductid:"+productid+",sort:"+sort+"");
			simproductBean.setAppkey("1");
			simproductBean.setRequestid(requestid);
			simproductBean.setModule(module);
			simproductBean.setPlatform(platform);
			simproductBean.setLimit("0,10");
			
			simproductCall.setData(simproductBean);
			simproductCall.callService();
			
			Logger.verifyEquals("OK", simproductCall.getStatus(), "验证接口返回状态是否正常");
			
			JSONArray hitsAry = simproductCall.getHits();
			
			for(int i=1;i<=hitsAry.length();i++){
				
			 String info = hitsAry.get(i-1).toString();
			 JSONObject infoAry = new JSONObject(info);
			 
			 //获取接口返回的key校验返回字段
			  Logger.verifyEquals(true,infoAry.has("tag") , "验证第"+i+"条记录返回结果中有tag标签这个key");
			  Logger.verifyEquals(true,infoAry.has("sproductid") , "验证第"+i+"条记录返回结果中有sproductid关键字这个key");
			  Logger.verifyEquals(true,infoAry.has("source") , "验证第"+i+"条记录返回结果中有source值这个key");
			  
			}
		
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	
	@Test
	@Category(P1.class)
	@TestCase
	public void Tc_SimProduct_025() {
		Logger.start(true,"购物车失效商品相似商品推荐-验证返回的sproductid是否有效 ");
		try {
			//设置参数
			String productid = "06C3059A-9600-42D6-B944-40891894EB64";
			String requestid = "1111111";
			String module = "shoppingcarsimproduct";
			String platform = "appbuyer";
			String sort = "algo1";
			
			simproductBean.setInfo("userid:2712477,cookieid:22,idfa:33,imei:44,source:0,sproductid:"+productid+",sort:"+sort+"");
			simproductBean.setAppkey("1");
			simproductBean.setRequestid(requestid);
			simproductBean.setModule(module);
			simproductBean.setPlatform(platform);
			simproductBean.setLimit("0,10");
			
			simproductCall.setData(simproductBean);
			simproductCall.callService();
			
			Logger.verifyEquals("OK", simproductCall.getStatus(), "验证接口返回状态是否正常");
			
			for (int i = 1; i <= simproductCall.getHits().length(); i++) {

				String info = simproductCall.getHits().get(i - 1).toString();
				JSONObject infoAry = new JSONObject(info);
				
				//如果接口返回的source=1为商户查M端库。source=0为买手，查C端的库
				int sourcesInt =  (Integer) infoAry.get("source");
				
				String productId = (String) infoAry.get("sproductid");
				
				
				List<Map> ProductLists = null;
				if (sourcesInt==1) {
					//返回M端数据库里的商品信息
					 ProductLists = new SearchWapper().getProductBySellerId(0,"","",productId);
				}else{
					//返回C端数据库里的商品信息
					 ProductLists = new CSearchWapper().getProductById(productId);
				}
				
				Logger.verifyEquals(1, ProductLists.size(), "检查第"+i+"条商品id为："+productId+"的商品是否满足能都搜索出来的要求");
				
			}
		
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	
	@Test
	@Category(P1.class)
	@TestCase
	public void Tc_SimProduct_026() {
		Logger.start(true,"购物车失效商品相似商品推荐-验证接口分页 ");
		try {
			//设置参数
			String sproductid = "06C3059A-9600-42D6-B944-40891894EB64";
			String requestid = "1111111";
			String module = "shoppingcarsimproduct";
			String platform = "appbuyer";
			String sort = "algo1";
			int limit = 2;
			
			simproductBean.setInfo("userid:11,cookieid:22,idfa:33,imei:44,source:0,sproductid:"+sproductid+",sort:"+sort+"");
			simproductBean.setAppkey("1");
			simproductBean.setRequestid(requestid);
			simproductBean.setModule(module);
			simproductBean.setPlatform(platform);
			simproductBean.setLimit("0,"+limit+"");
			
			simproductCall.setData(simproductBean);
			simproductCall.callService();
			
			JSONArray hits = simproductCall.getHits();
			
			Logger.verifyEquals(limit, hits.length(), "检查接口返回记录数是否为每页所传数目");
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	
	
	@Test
	@Category(P1.class)
	@TestCase
	public void Tc_SimProduct_027() {
		Logger.start(true,"购物车失效商品相似商品推荐-验证返回商品是否满足匹配查找商品的二级类目或者品牌 ");
		/***
		 * 返回商品匹配规则：1.优先匹配与查找商品的二级类目相同的或者与查找商品品牌相同的商品。》2.匹配查找商品同商家的商品
		 * 排序规则：针对第一种方式会先从ex中取500条数据，然后通过根据商品名关键字匹配度高的排序，取前20个
		 * 针对第二种方式，直接取前20个
		 */
		
		try {
			//设置参数
			String requestid = "1111111";
			String module = "shoppingcarsimproduct";
			String platform = "appbuyer";
			String sort = "algo1";
			int limit = 20;
			//该商品是m端商品，二级类目是1252，品牌是10430
			String sproductid = "06C3059A-9600-42D6-B944-40891894EB64";
			
			simproductBean.setInfo("userid:11,cookieid:22,idfa:33,imei:44,source:0,sproductid:"+sproductid+",sort:"+sort+"");
			simproductBean.setAppkey("1");
			simproductBean.setRequestid(requestid);
			simproductBean.setModule(module);
			simproductBean.setPlatform(platform);
			simproductBean.setLimit("0,"+limit);
			
			simproductCall.setData(simproductBean);
			simproductCall.callService();
			
			//获取参数中的productid所属的类目和品牌
			List<Map> productInfo = new SearchWapper().selectProductInfo(sproductid);
			int paramIbrandid = (Integer) productInfo.get(0).get("iBrandId");
			int paramICategoryId = (Integer) productInfo.get(0).get("iCategoryId");
			
			//JSONArray hits = simproductCall.getHits();
			//验证返回的商品二级类目是否为1252或者品牌是否为10430
			//注意区分c端还是m端商品
			for (int i = 1; i <= simproductCall.getHits().length(); i++) {

				String info = simproductCall.getHits().get(i - 1).toString();
				JSONObject infoAry = new JSONObject(info);
				
				//如果接口返回的source=1为商户查M端库。source=0为买手，查C端的库
				int sourcesInt = (Integer) infoAry.get("source");
				
				String productId = (String) infoAry.get("sproductid");
				
				List<Map> ProductLists = null;
				if (sourcesInt==1) {
					//返回M端数据库里该商品信息
					ProductLists = new SearchWapper().selectProductInfo(productId);
					int ibrandid = (Integer) ProductLists.get(0).get("iBrandId");
					int iCategoryId = (Integer) ProductLists.get(0).get("iCategoryId");
					
					
					if(paramIbrandid !=ibrandid && paramICategoryId !=iCategoryId){
						Logger.verifyEquals((paramIbrandid ==ibrandid || paramICategoryId ==iCategoryId),(paramIbrandid !=ibrandid && paramICategoryId !=iCategoryId) , 
								"验证第"+i+"条返回商品能够匹配到品牌或者类目");
					}
					
					if (paramIbrandid ==ibrandid || paramICategoryId ==iCategoryId) {
						Logger.verifyEquals(true, (paramIbrandid ==ibrandid || paramICategoryId ==iCategoryId), 
								"检查第"+i+"条返回商品品牌和类目能够匹配参数商品的品牌或类目.返回商品的类目："+iCategoryId+",品牌："+ibrandid+"。检索商品的类目:"+paramICategoryId+",品牌:"+paramIbrandid);
					}
			
				}else{
					//返回C端数据库里该商品信息
					ProductLists = new SearchWapper().selectProductInfo(productId);
					int ibrandid = (Integer) ProductLists.get(0).get("iBrandId");
					int iCategoryId = (Integer) ProductLists.get(0).get("iCategoryId");
					
					
					if(paramIbrandid !=ibrandid && paramICategoryId !=iCategoryId){
						Logger.verifyEquals((paramIbrandid ==ibrandid || paramICategoryId ==iCategoryId),(paramIbrandid !=ibrandid && paramICategoryId !=iCategoryId) , 
								"验证第"+i+"条返回商品能够匹配到品牌或者类目");
					}
					
					if (paramIbrandid ==ibrandid || paramICategoryId ==iCategoryId) {
						Logger.verifyEquals(true, (paramIbrandid ==ibrandid || paramICategoryId ==iCategoryId), 
								"检查第"+i+"条返回商品品牌和类目能够匹配参数商品的品牌或类目.返回商品的类目："+iCategoryId+",品牌："+ibrandid+"。检索商品的类目:"+paramICategoryId+",品牌:"+paramIbrandid);
					}
					
				}
				
			}
			
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	
	@Test
	@Category(P1.class)
	@TestCase
	public void Tc_SimProduct_028() {
		Logger.start(true,"购物车失效商品相似商品推荐-验证检索无匹配品牌和类目时，需要匹配商家id ");
		/***
		 * 返回商品匹配规则：1.优先匹配与查找商品的二级类目相同的或者与查找商品品牌相同的商品。》2.匹配查找商品同商家的商品
		 * 排序规则：针对第一种方式会先从ex中取500条数据，然后通过根据商品名关键字匹配度高的排序，取前20个
		 * 针对第二种方式，直接取前20个
		 */
		
		try {
			//设置参数
			String requestid = "1111111";
			String module = "shoppingcarsimproduct";
			String platform = "appbuyer";
			String sort = "algo1";
			int limit = 20;
			//该商品是m端商品，二级类目是1077，品牌是13259，该类目下只有2个有效商品，该品牌下有2个商品
			String sproductid = "06C3059A-9600-42D6-B944-40891894EB64";
			
			simproductBean.setInfo("userid:11,cookieid:22,idfa:33,imei:44,source:0,sproductid:"+sproductid+",sort:"+sort+"");
			simproductBean.setAppkey("1");
			simproductBean.setRequestid(requestid);
			simproductBean.setModule(module);
			simproductBean.setPlatform(platform);
			simproductBean.setLimit("0,"+limit);
			
			simproductCall.setData(simproductBean);
			simproductCall.callService();
			
			//获取检索商品的商家id
			List<Map> productInfo = new SearchWapper().selectProductInfo(sproductid);
			int paramIUserId = (Integer) productInfo.get(0).get("iUserId");
			int paramIbrandid = (Integer) productInfo.get(0).get("iBrandId");
			int paramICategoryId = (Integer) productInfo.get(0).get("iCategoryId");
			
			for (int i = 1; i <= simproductCall.getHits().length(); i++) {

				String info = simproductCall.getHits().get(i - 1).toString();
				JSONObject infoAry = new JSONObject(info);
				
				//如果接口返回的source=1为商户查M端库。source=0为买手，查C端的库
				int sourcesInt =  (Integer) infoAry.get("source");
				
				String productId = (String) infoAry.get("sproductid");
				
				List<Map> ProductLists = null;
				if (sourcesInt==1) {
					//返回M端数据库里该商品信息
					ProductLists = new SearchWapper().selectProductInfo(productId);
					int ibrandid = (Integer) ProductLists.get(0).get("iBrandId");
					int iCategoryId = (Integer) ProductLists.get(0).get("iCategoryId");
					int iuserId =  (Integer) ProductLists.get(0).get("iUserId");
					
					if(paramIbrandid !=ibrandid && paramICategoryId !=iCategoryId && paramIUserId !=iuserId){
						Logger.verifyEquals((paramIbrandid ==ibrandid || paramICategoryId ==iCategoryId),(paramIbrandid !=ibrandid && paramICategoryId !=iCategoryId) , 
								"验证第"+i+"条返回商品的品牌或者类目或者商家id与检索商品一致");
					}
					
					if (paramIbrandid ==ibrandid || paramICategoryId ==iCategoryId || paramIUserId==iuserId) {
						Logger.verifyEquals(true, (paramIbrandid ==ibrandid || paramICategoryId ==iCategoryId || paramIUserId==iuserId), 
								"检查第"+i+"条返回商品品牌或类目或商家id能够匹配参数商品的品牌或类目或商家id.返回商品的类目："+iCategoryId+",品牌："+ibrandid+"，商家id："+iuserId+"。检索商品的类目:"+paramICategoryId+",品牌:"+paramIbrandid+",商家id:"+paramIUserId);
					}
			
				}else{
					//返回C端数据库里该商品信息
					ProductLists = new SearchWapper().selectProductInfo(productId);
					int ibrandid = (Integer) ProductLists.get(0).get("iBrandId");
					int iCategoryId = (Integer) ProductLists.get(0).get("iCategoryId");
					int iuserId =  (Integer) ProductLists.get(0).get("iUserId");
					
					if(paramIbrandid !=ibrandid && paramICategoryId !=iCategoryId && paramIUserId !=iuserId){
						Logger.verifyEquals((paramIbrandid ==ibrandid || paramICategoryId ==iCategoryId),(paramIbrandid !=ibrandid && paramICategoryId !=iCategoryId) , 
								"验证第"+i+"条返回商品的品牌或者类目或者商家id与检索商品一致");
					}
					
					if (paramIbrandid ==ibrandid || paramICategoryId ==iCategoryId || paramIUserId==iuserId) {
						Logger.verifyEquals(true, (paramIbrandid ==ibrandid || paramICategoryId ==iCategoryId || paramIUserId==iuserId), 
								"检查第"+i+"条返回商品品牌或类目或商家id能够匹配参数商品的品牌或类目或商家id.返回商品的类目："+iCategoryId+",品牌："+ibrandid+"，商家id："+iuserId+"。检索商品的类目:"+paramICategoryId+",品牌:"+paramIbrandid+",商家id:"+paramIUserId);
					}
					
				}
				
			}
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	
}
